package com.tledu.springboot04.service;

import com.tledu.springboot04.core.exception.CustomException;
import com.tledu.springboot04.domain.User;
import com.tledu.springboot04.mapper.UserMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Antg
 * @date 2021/8/25  17:46
 */
@Service
@AllArgsConstructor
public class UserServiceImpl implements UserService {
    private final UserMapper userMapper;

    @Override
    public User login(String username, String password) {
        User user = userMapper.findByUserName(username);
        if (user == null) {
            throw new CustomException("用户不存在", 500);
        }
        if (!password.equals(user.getPassword())) {
            throw new CustomException("密码错误", 500);
        }
        return user;
    }

    @Override
    public List<User> list(User user) {
        return userMapper.list(user);
    }
    
    @Override
    public int del(Integer id) {
        return userMapper.del(id);
    }
}
